using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace PKGames
{
	public class Matchable : MonoBehaviour
	{
		[SerializeField]
		private AnimationClip _errorAnimation;

		[SerializeField]
		private AnimationClip _successAnimation;

		private List<string> _tags = new List<string>();

		private Animation _animation;

		public List<string> Tags => _tags;

		private void Awake()
		{
			_animation = GetComponent<Animation>();
			if (_errorAnimation != null)
			{
				_animation.AddClip(_errorAnimation, _errorAnimation.name);
			}
		}

		public bool ItsAMatch(Matchable otherMatchable)
		{
			foreach (string tag in Tags)
			{
				foreach (string tag2 in otherMatchable.Tags)
				{
					if (string.Equals(tag, tag2))
					{
						return true;
					}
				}
			}
			return false;
		}

		public void AddTags(List<string> tagsToAdd)
		{
			_tags.AddRange(tagsToAdd);
		}

		public IEnumerator OnError()
		{
			if (_errorAnimation != null)
			{
				_animation.Play(_errorAnimation.name);
				while (_animation.isPlaying)
				{
					yield return null;
				}
			}
		}

		public IEnumerator OnSuccess()
		{
			if (_successAnimation != null)
			{
				_animation.Play(_successAnimation.name);
				while (_animation.isPlaying)
				{
					yield return null;
				}
			}
		}
	}
}
